﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jumpton.SFA.Server.BusinessRule.CallRoute;
using Jumpton.SFA.Server.BusinessRule;
public partial class Route : PageBase
{
    protected String Body = null;
         
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Data.IDataReader reader = null;
            
        try
        {
            int uid = -1;
            if (!int.TryParse(Request.QueryString[CommonString.UID], out uid))
                return;
            reader = new RouteManager().GetAllRoutesCustomers(null, uid, (bool?)true);
            String HeaderFormat = "<li><h3>{0}</h3><p>{1}</p><ol data-role=\"listview\">";
            String LineFormat = "<li><a href='CustomerDetail.aspx?{1}'>{0}</a></li>";
            String LastRouteNumber = null;
            String Header = null;
					
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            System.Text.StringBuilder DetailBuilder = new System.Text.StringBuilder();
            //获取当前请求的查询字符串列表
            System.Collections.Specialized.NameValueCollection list = QueryStringHelper.DecodeQueryString(Request.QueryString);
            while (reader.Read())
            {
                if (reader["ROUTE_NUMBER"].ToString() != LastRouteNumber)
                {
                    LastRouteNumber = reader["ROUTE_NUMBER"].ToString();
                    if (Header != null)
                    {
                        sb.Append(String.Format("{0}{1}</ol></li>",Header, DetailBuilder.ToString()));
                        

                    }
                    Header = "";
                    String Route_Force = reader["ROUTE_FORCE"].ToString();
                    String Summary = null;
                    if (reader["VALID_DATE"] != DBNull.Value)
                    {
                        Summary = (Route_Force == "1" ? "顺序拜访" : "非序拜访") + " 拜访时间" + BusinessLogic.GetDateTime(reader["VALID_DATE"].ToString(), "yyyyMMddHHmmss", "yyyy年MM月dd日");
                    }
                    else
                    {
                        Summary = Route_Force == "1" ? "顺序拜访" : "非序拜访";
                    }
                    Header = String.Format(HeaderFormat, reader["DESCRIPTION"], Summary);
                    DetailBuilder.Clear();
                }

                System.Collections.Specialized.NameValueCollection newlist = QueryStringHelper.DecodeQueryString(Request.QueryString);
               
                newlist.Add("CID",reader["ID"].ToString());
                newlist.Add(CommonString.REQUESTKEY, QueryStringHelper.BuilderRequestKey(newlist, VERSION));
                String QueryString = QueryStringHelper.BuilderQueryString(newlist);
                DetailBuilder.AppendFormat(LineFormat, reader["NAME"], QueryString);
            }
            sb.Append(String.Format("{0}{1}</ol></li>", Header, DetailBuilder.ToString()));
            Body = sb.ToString();
            this.DataBind();
        }
        catch(Exception err)
        {

        }
        finally
        {
            if (reader != null)
            {
                reader.Close();
                reader.Dispose();
                reader = null;

            }
        }
    }
}